<template>
	<view class="">
		<!-- 地址定位 -->
		<uniLocation :address="showAddrtext" v-on:setAddress="tosearchaddress"></uniLocation>
		<!-- swiper组件 -->
		<swiper class="swiper" :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000" indicator-color="rgba(38, 202, 211, 0.21)"
		 indicator-active-color="rgba(38, 202, 211,.9)">
			<swiper-item v-for="(banner,index) in swiperList" :key="index">
				<view class="swiper-item">
					<navigator :url="banner.ProUrl">
						<image class="img" :src="banner.ImgUrl" mode=""></image>
					</navigator>
				</view>
			</swiper-item>
		</swiper>

		<button type="warn" @click="topay()">去微信支付</button>
		<button type="primary" @click="towebview()">web-view跳转</button>
		<button type="primary" @click="toshare()">去分享</button>
		<button type="primary" @tap="showCalendar()">打开日历</button>
		<text>{{deliveryDate}}</text>
		<button type="primary" @tap="decodeRechtext()">富文本解析</button>
		<share ref="sharesdk" :contentHeight="580"></share>
		<calendar ref="calendar" :agoDayHide="agoDayHide" :futureDayHide="futureDayHide" v-on:choseDay="chooseDeliveryDate"></calendar>
	</view>

</template>

<script>
	import uniLocation from '@/components/tabbar/index/auto-location.vue'
	import share from '@/components/share.vue'
	import Calendar from '@/components/calendar/uni-calendar.vue';
	import initloaction_api from '@/api/map/init.js'
	import swiper_api from '@/api/swiper/index.js'
	import dateParse from '@/util/date/date-parse.js'
	export default {
		data() {
			return {
				showAddrtext: '重新定位',
				swiperList: [],
				isMpweixin: false,
				nowdate: '2019-05-18',
				agoDayHide: '0',
				futureDayHide: '0',
				deliveryDate: ''
			}
		},
		components: {
			uniLocation,
			share,
			Calendar
		},
		onShow() {
			this.$setTitle("嗨焙鲜生·精选")
		},
		onLoad() {
			this.initLoaction()
			// #ifdef H5
			this.isMpweixin = true
			this.initShare()
			// #endif
			// #ifdef MP-WEIXIN
			this.isMpweixin = false
			// #endif
		},
		onPullDownRefresh() {
			this.initLoaction(1)
		},
		//微信小程序分享
		onShareAppMessage: function(res) {
			if (res.from === 'button') {}
			return {
				title: '六一儿童节,哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈',
				path: '/pages/tabBar/cart?sharesdk=1',
				imageUrl: '/static/share/1.png',
				success: function(res) {
					console.log('成功', res);
				}
			};
		},
		methods: {
			initLoaction(reload = false) {
				let that = this
				let p = {
					start() {
						that.showAddrtext = '正在定位...'
					},
					success(addr) {
						uni.stopPullDownRefresh();
						that.showAddrtext = addr.title || '重新定位'

						that.initSwiperData('上海')
					},
					fail() {
						uni.stopPullDownRefresh();
						that.initSwiperData('上海')
						that.showAddrtext = '重新定位'
						uni.showModal({
							title: '地址定位失败',
							content: '未获取到当前定位地址，请手动添加，谢谢',
							showCancel: false,
							confirmText: '去手动添加',
							confirmColor: '#e64340',
							success() {
								uni.navigateTo({
									url: '../../pages/searchaddress/searchaddress'
								})
							}
						})
					}
				}

				initloaction_api.initMyLocation(reload, p)
			},
			//初始化swiper数据
			initSwiperData() {
				this.swiperList = []
				swiper_api.getSwiperList('1', (list) => {
					this.swiperList = list
				})
			},
			gotoUrl(data) {

			},
			tosearchaddress() {
				uni.navigateTo({
					url: '/pages/searchaddress/searchaddress'
				})
			},
			topay() {
				let from_uri = '',
					to_uri = '/pages/weixin/weixin?orderid=11111111111111'
				uni.navigateTo({
					url: '/pages/weixin/redirect?to_uri=' + encodeURIComponent(to_uri)
				})
			},
			towebview() {
				uni.navigateTo({
					url: '/pages/webview/webview?redirectUrl=' + encodeURIComponent(
						'https://happycs.bestcake.com/static/h5/index.html')
				})
			},
			toshare() {
				this.$refs.sharesdk.toggleMask();
			},
			initShare() {
				this.$ShareSdk.Share({
					title: '六一儿童节',
					content: '六一儿童节,哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈',
					desc: '哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈',
					link: '/pages/tabBar/cart?sharesdk=1',
					success() {

					}
				})
			},
			showCalendar() {
				let now = new Date('2019-05-30')
				//当天开始显示 -1 隔天显示 0 
				let now1 = dateParse.addDays(now, -1)
				this.agoDayHide = dateParse.getTimeshort(now1)
				let futureday = dateParse.addDays(now, 60)
				this.futureDayHide = dateParse.getTimeshort(futureday)
				this.$refs.calendar.showCalendarfn()
			},
			chooseDeliveryDate(val) {
				this.deliveryDate = val

				uni.showLoading({
					mask: true
				})
				setTimeout(() => {
					uni.hideLoading()
					this.$refs.calendar.showCalendarfn()
				}, 500)
			},
			decodeRechtext() {
				uni.navigateTo({
					url: '../../pages/community/community'
				})
			}
		}
	}
</script>

<style lang="scss" scoped="">
	.showAddrtext {
		height: 100upx;
		line-height: 100upx;
	}

	.swiper {
		height: 380upx;
		border-radius: 5upx;
		background: #fff;
	}

	.img {
		width: 100%;
	}
</style>
